package com.goods.controller.business;

import com.goods.business.service.HealthService;
import com.goods.common.model.business.Health;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.JWTUtils;
import com.goods.common.vo.business.HealthVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author XiaoHong
 * @description 健康宝贝接口
 * @date 2022/2/18
 */
/*
*

* */
@RestController
@Api(tags = "健康宝贝接口")
@RequestMapping("/business/health")
public class HealthController {
    @Autowired
    private HealthService healthService;
    //http://www.localhost:8989/business/health/isReport
    //是否已经报备过了
    @GetMapping("/isReport")
    public ResponseBean<Health> isReport(@RequestHeader(value = "Authorization",required = false)String token ){
        String username = JWTUtils.getUsername(token);
        Health health = healthService.isReport(username);
        return ResponseBean.success(health);
    }

    //http://www.localhost:8989/business/health/report
    //立即打卡
    @PostMapping("/report")
    public ResponseBean report(
            @RequestBody Health health,
            @RequestHeader(value = "Authorization",required = false)String token ){
        String username = JWTUtils.getUsername(token);
        healthService.report(health,username);
        return ResponseBean.success();
    }

    //http://www.localhost:8989/business/health/history?pageSize=4&pageNum=1
    //签到记录
    @GetMapping("/history")
    public ResponseBean<PageVO<Health>> history(
            @RequestHeader(value = "Authorization",required = false)String token,
            Integer pageSize,Integer  pageNum){
        String username = JWTUtils.getUsername(token);
        PageVO<Health> healthPageVO= healthService.history(username,pageSize,pageNum);
        return ResponseBean.success(healthPageVO);
    }
}
